package com.example.shop_2211.fgViewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.GetUserEntityResult
import com.example.base.entity.ImageEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch
import okhttp3.MultipartBody

class MineViewModel :BaseViewModel(){
    //获取用户信息
    val getUserSuccess = MutableLiveData<GetUserEntityResult>()
    val getUserFail = MutableLiveData<String>()
    fun getUser(){
        viewModelScope.launch {
            try {
                getUserSuccess.value = apiService.getUser()
            }catch (e:Exception){
                getUserFail.value = e.message
            }
        }
    }
    val imageSuccess = MutableLiveData<ImageEntityResult>()
    val imageFail = MutableLiveData<String>()
    fun image(model:String,pid:String,part:MultipartBody.Part){
        viewModelScope.launch {
            try {
                imageSuccess.value = apiService.image(model,pid,part)
            }catch (e:Exception){
                imageFail.value = e.message
            }
        }
    }
}